<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('applications', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('project_id')->default(0);
            $table->unsignedBigInteger('source_id')->default(0);
            $table->unsignedBigInteger('user_id')->comment('申请人 ID'); // 关联到用户表的申请人 ID
            $table->string('type', 50)->comment('申请类型');
            $table->string('source', 50)->comment('来源');
            $table->string('model')->comment('Model');
            $table->string('reason')->nullable()->comment('申请原因');
            $table->decimal('price', 10, 2)->default(0)->comment('支付金额/发票金额');
            // 付款方式，如银行转账、支票等
            $table->string('payment_type')->default('/')->nullable()->comment('支付类型');
            $table->string('pay_info')->default('/')->nullable()->comment('支付信息');
            $table->string('pay_date')->nullable()->comment('支付日期');
            $table->string('invoice_type')->default('/')->nullable()->comment('发票类型');
            $table->string('invoice_numbers')->default('/')->nullable()->comment('发票编号');
            $table->string('invoice_file')->default('')->nullable()->comment('发票文件');
            $table->string('receipt')->default('')->nullable()->comment('回单/收据文件');
            // 收款方信息，包括收款方名称、银行账号、开户行等
            $table->string('status', 20)->default('pending')->comment('申请状态，如 pending（待审核）、approved（已批准）、rejected（已拒绝）');
            $table->timestamps();
        });

        Schema::create('application_processess', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('project_id')->comment('ID');
            $table->string('type', 50)->comment('申请类型');
            $table->integer('level')->default(0)->comment('审批级别');
            $table->integer('role_id')->default(0)->comment('审批角色');
            $table->integer('user_id')->default(0)->comment('审批用户');
            $table->timestamps();
        });

        Schema::create('application_records', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('application_id')->comment('申请表 ID');
            $table->integer('role_id')->default(0)->comment('审批角色');
            $table->unsignedBigInteger('reviewer_id')->default(0);
            $table->integer('level')->default(0)->comment('审批级别');
            $table->string('status', 20)->default('pending')->comment('审批结果，如 approved、rejected');
            $table->text('comment')->nullable()->comment('审批意见');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('applications');
        Schema::dropIfExists('application_processess');
        Schema::dropIfExists('application_records');
    }
};
